<template>
  <div>
    <div class="punch-top">
      <h4 style="text-align: left; color: #126bff; margin-bottom: 20px">
        人员预警信息
      </h4>
      <el-form
        id="punch"
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="115px"
        style="display: flex; flex-wrap: wrap"
      >
        <el-form-item
          label="人员姓名:"
          prop="peopleName"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.peopleName"
            placeholder="请输入人员姓名"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="身份证号:"
          prop="idCard"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.idCard"
            placeholder="请输入身份证号"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="关注人员类型 :"
          prop="gzrylx"
          clearable
          style="width: 450px; float: left"
        >
          <el-select
            v-model="formData.gzrylx"
            placeholder="请选择关注人员类型"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
            <el-option
              v-for="item in gzrylx"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item
          label="预警时段:"
          prop="time"
          style="width: 450px; float: left"
        >
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-d"
            value-format="yyyy-MM-d"
            :style="{ width: '300px' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
          ></el-date-picker>
        </el-form-item>

        <el-form-item size="medium" style="float: right">
          <el-button @click="resetForm()" id="reset">重置</el-button>
          <el-button
            type="primary"
            @click="submitForm(formData)"
            id="submitForm"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="punch-content" style="width: 100%">
      <el-table
        :data="
          tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        style="width: 100%"
      >
        <el-table-column prop="id" label="序号" width="100">
          <template slot-scope="scope">
            {{ scope.$index + 1 + (currentPage - 1) * pageSize }}
          </template>
        </el-table-column>
        <el-table-column prop="photo" label="关注人员">
          <template v-slot:default="scope">
            <el-image
              style="
                width: 50px;
                height: 50px;
                padding: 5px;
                box-sizing: border-box;
              "
              :src="scope.row.photo"
              v-if="scope.row.photo"
              :preview-src-list="[scope.row.photo]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="photo2" label="抓拍图像">
          <template v-slot:default="scope">
            <el-image
              style="
                width: 50px;
                height: 50px;
                padding: 5px;
                box-sizing: border-box;
              "
              :src="scope.row.photo"
              v-if="scope.row.photo"
              :preview-src-list="[scope.row.photo]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="人员姓名"> </el-table-column>
        <el-table-column prop="xsd" label="相似度"> </el-table-column>
        <el-table-column
          prop="personnelCharacteristics"
          label="人员特征"
          v-if="false"
        >
        </el-table-column>
        <el-table-column prop="gzrylx" label="关注人员类型" width="200">
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.showIdCard">{{ scope.row.idCard }}</span>
            <span v-else
              >{{ scope.row.idCard.substr(0, 6) }}********{{
                scope.row.idCard.substr(14)
              }}</span
            >
            <el-button
              type="text"
              icon="el-icon-view"
              @click="scope.row.showIdCard = !scope.row.showIdCard"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="处理状态">
          <template v-slot="scope">
            <!-- <el-tag size="medium">{{ scope.row.name }}</el-tag> -->
            <!-- @click="pass(scope.row)" -->
            <el-tag
              size="medium"
              v-if="scope.row.status == 1"
              style="
                width: 50px;
                height: 30px;
                background: #ffffff;
                border-radius: 4px 4px 4px 4px;
                opacity: 1;
                color: #1cdc7c;
                border: 1px solid #1cdc7c;
                padding: 0;
                cursor: pointer;
              "
              >已处理</el-tag
            >
            <el-tag
              size="medium"
              v-if="scope.row.status == 0"
              @click="Topass(scope.row)"
              style="
                width: 50px;
                height: 30px;
                background: #ffffff;
                border-radius: 4px 4px 4px 4px;
                opacity: 1;
                border: 1px solid #ff4444;
                color: #ff4444;
                padding: 0;
                cursor: pointer;
              "
              >未处理</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="yjsb" label="预警设备"> </el-table-column>
        <el-table-column prop="yjdd" label="预警地点"> </el-table-column>
        <el-table-column prop="yjss" label="预警时间"> </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" v-if="scope.row.status == 0"
              >去处理</el-button
            >
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[1, 2, 4, 8]"
        :page-size="pageSize"
        layout="total, prev, pager, next, sizes"
        :total="tableData.length"
        style="float: right; margin-top: 20px"
      >
      </el-pagination>
    </div>
    <!-- 详情弹窗 -->
    <div>
      <detailDialog
        :warnVsible="Visible"
        :detail="detaile"
        :personnelWarningVisible="personnelWarningVisible"
        @showIdCard="showIdCard"
        @handel="handel"
        @hulue="hulue"
        @Confirm="Confirm"
      ></detailDialog>
    </div>
  </div>
</template>
<script>
// import { signLog } from "@/api/police";
import { Loading } from "element-ui";
import detailDialog from "@/components/detailDetail";
export default {
  name: "punchLog",
  components: { detailDialog },
  data() {
    return {
      Visible: false,
      personnelWarningVisible: false,
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      currentPage4: 4,
      currentPage: 1,
      pageSize: 4,
      // 条件搜索表单
      formData: {
        gzrylx: "", // 所属行政区域
        peopleName: "", // 单位名称
        idCard: "", // 姓名
        time: "", // 时间
        page: "1",
        pagesize: "20",
      },
      // 将条件搜索表单中的time 转为开始时间  截止时间
      searchData: {
        gzrylx: "", //所属行政区域
        peopleName: "", // 单位名称
        idCard: "", // 上报人姓名
        begin_time: "", // 开始时间
        end_time: "", // 结束时间
        page: "1",
        pagesize: "20",
      },
      detaile: {}, // 详情
      tableData: [
        {
          photo: require("@/assets/pagesImg/zddw.png"),
          photo2: require("@/assets/pagesImg/zddw.png"),
          name: "袁婷宣",
          sex: "女",
          nation: "回族",
          personnelCharacteristics: "身高160左右",
          xsd: "95%",
          gzrylx: "精神异常",
          idCard: "188025123456789060",
          yjsb: "RXSB-3320",
          yjdd: "廊坊市第一小学",
          yjss: "2023-09-03 15:30:56",
          status: 0,
          showIdCard: false,
        },
        {
          photo: require("@/assets/pagesImg/zddw.png"),
          photo2: require("@/assets/pagesImg/zddw.png"),
          name: "李涵",
          sex: "女",
          nation: "回族",
          personnelCharacteristics: "身高160左右",
          xsd: "95%",
          gzrylx: "在逃",
          idCard: "188025123456789060",
          yjsb: "RXSB-3320",
          yjdd: "廊坊市第一小学",
          yjss: "2023-09-03 15:30:56",
          status: 1,
          showIdCard: false,
        },
        {
          photo: require("@/assets/pagesImg/zddw.png"),
          photo2: require("@/assets/pagesImg/zddw.png"),
          name: "李星",
          sex: "男",
          nation: "汉族",
          personnelCharacteristics: "身高160左右",
          xsd: "98%",
          gzrylx: "涉黄",
          idCard: "188025123456789060",
          yjsb: "RXSB-3320",
          yjdd: "廊坊市第一小学",
          yjss: "2023-09-03 15:30:56",
          status: 0,
          showIdCard: false,
        },
        {
          photo: require("@/assets/pagesImg/zddw.png"),
          photo2: require("@/assets/pagesImg/zddw.png"),
          name: "范燕",
          sex: "女",
          nation: "回族",
          personnelCharacteristics: "身高160左右",
          xsd: "93%",
          gzrylx: "涉赌",
          idCard: "188025123456789060",
          yjsb: "RXSB-3320",
          yjdd: "廊坊市第一小学",
          yjss: "2023-09-03 15:30:56",
          status: 1,
          showIdCard: false,
        },
      ], // 表格数据存放
      dialogVisible: false,
      // 行政区域代码
      gzrylx: [
        {
          text: "在逃",
          value: "在逃",
        },
        {
          text: "精神异常",
          value: "精神异常",
        },
        {
          text: "涉黄",
          value: "涉黄",
        },
        {
          text: "涉毒",
          value: "涉毒",
        },
        {
          text: "涉赌",
          value: "涉赌",
        },
      ],
    };
  },
  watch: {
    $route(to, from) {
      console.log(to, from);
    },
  },
  created() {},
  mounted() {
    this.initdata();
  },

  methods: {
    handel(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.personnelWarningVisible = e;
    },
    Confirm(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.personnelWarningVisible = e;
    },
    hulue(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.personnelWarningVisible = e;
    },
    showIdCard(e) {
      console.log(e);
      this.showIdCard = e;
    },
    handleClick(row) {
      console.log(row);
      this.Visible = !this.Visible;
      this.personnelWarningVisible = !this.personnelWarningVisible;
      this.$nextTick(() => {
        this.detaile = row;
      });
    },
    // 数据初始化
    initdata() {},
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    // 将搜索条件格式处理
    formToSearch(formData) {
      this.searchData.gzrylx = formData.gzrylx;
      this.searchData.peopleName = formData.peopleName;
      this.searchData.idCard = formData.idCard;
      // this.searchData.token = this.$VueCookies.get("token");
      this.searchData.page = 1;
      this.searchData.pagesize = 20;
      if (formData.time == "" || formData.time == null || formData.time == []) {
        this.searchData.end_time = "";
        this.searchData.begin_time = "";
      } else {
        this.searchData.end_time = formData.time[1];
        this.searchData.begin_time = formData.time[0];
      }
      return this.searchData;
    },
    submitForm(formData) {
      this.tableData = []; //清空列表页面的数据。。。。。。。。。。。。。。。。。。。。

      // let loadingInstance = Loading.service({
      //   target: document.querySelector(".el-table__body-wrapper"),
      // });
      console.log(this.formToSearch(formData));
      // let that = this;
      // signLog(this.formToSearch(formData)).then((res) => {
      //   if (res.code == 200) {
      //     console.log(res);
      //     // this.tableData = res.data;
      //     res.data.res.forEach((item, index) => {
      //       res.data.res[index].create_time = that
      //         .$moment(item.create_time * 1000)
      //         .format("YYYY-MM-DD HH:mm:ss");
      //       // console.log(moment(item.create_time * 1000).format("YYYY-MM-DD"));
      //     });
      //     res.data.res.forEach((item) => {
      //       that.tableData.push(item);
      //     });
      //     this.currentPage = 1; // 重置到第一页
      //     loadingInstance.close();
      //   }
      // });
    },
    Topass() {
      console.log("去处理");
    },
    // pass() {
    //   console.log("以处理");
    // },
    resetForm() {
      this.$refs["elForm"].resetFields();
      this.formToSearch(this.formData);
      this.initdata();
      // this.tableData = this.initTableData;
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      if (Math.ceil(this.tableData.length / this.pageSize) == val) {
        console.log("最后一页");
        this.searchData.page = parseInt(this.searchData.page) + 1;
        this.initdata();
      }
      this.currentPage = val;
      // console.log(`当前页: ${val}`);  // 分页功能
      // // if(val == )
      // console.log(this.tableData.length / this.pageSize);
      // console.log(Math.ceil(this.tableData.length / this.pageSize));
      // if (Math.ceil(this.tableData.length / this.pageSize) == val) {
      //   console.log("最后一页");
      //   this.searchData.pagesize = parseInt(this.searchData.pagesize) + 20;
      //   this.initdata();
      // }
      // this.currentPage = val;
    },
  },
};
</script>
<style scoped lang="scss">
#punch {
  /deep/.el-form-item__content {
    margin-left: 0px !important;
  }
}
.punch-top {
  // border: 1px red solid;
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
// .punch-top {
//   width: calc(100%);
// }
// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
.punch-top /deep/[data-v-21354b7e] .el-form-item__content {
  border: none;
  width: auto;
  padding-left: 20px;
}
/deep/.el-form-item__label {
  // border: 1px red solid;
  width: 104px !important;
}
.punch-content {
  margin-top: 20px;
  // border: 1px red solid;
  height: 500px;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}

.el-table .el-table__cell {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
}
.upIpfo {
  display: flex;
  width: 100%;
  // border: 1px red solid;
  justify-content: space-between;
}
/deep/.imgPhoto {
  display: inline;
  vertical-align: text-top !important;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  // border: 1px red solid;
  display: inline-block;
  // background-color: skyblue;
}
/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}
// /deep/.el-table__row {
//   border: 1px red solid !important;
// }
/deep/.el-dialog {
  border-radius: 15px !important;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 0 20px 20px 20px !important;
}
// /deep/.el-dialog__body tbody > .el-table__row {
//   color: red !important;
//   /deep/.el-table_1_column_5 {
//     color: red !important;
//   }
// }
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
  right: 20px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
  border-radius: 6px !important;
}
// el-table_1_column_5   el-table__cell
.rowText {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /*第几行裁剪*/
  -webkit-box-orient: vertical;
}
::v-deep.el-table th.el-table__cell {
  background-color: #ecf5ff !important;
  width: 64px !important;
  height: 21px !important;
  font-size: 16px !important;
  color: #13213b !important;
}
</style>
